<template>
  <div class="content" :class="{ 'is-mobile': isMobile }">
    <heads :current="1"></heads>
    <div class="main">
      <div class="product-list">
        <div class="product-item" v-for="(item, index) in products" :key="index" >
          <div class="product-image">
            <img :src="item.post_url" :alt="item.name">
          </div>
          <div class="product-info">
            <h2 class="product-name">{{ item.name }}</h2>
            <div class="product-desc">{{ item.desc }}</div>
            <div class="product-meta">
              <span class="duration">{{ $t('booking.duration') }}: {{ item.duration }}h</span>
            </div>
            <div class="product-footer">
              <div class="price">
                <span class="amount">${{ item.price }}</span>
              </div>
              <el-button type="primary" class="book-btn" @click="selectProduct(item)">{{ $t('booking.bookNow') }}</el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <foot></foot>
  </div>
</template>

<script>
import { http } from '@/api/api.js'

export default {
  name: 'booking',
  data() {
    return {
      isMobile: false,
      products: [

      ],
      loading: false
    }
  },
  created() {
    http.ship.list().then(res => {
      this.products = res.data
      console.log('this.products',this.products)
    })
  },
  methods: {
    checkDevice() {
      this.isMobile = window.innerWidth <= 750
    },
    async selectProduct(item) {
      if (item.code === 'Custom') {
        this.$router.push({
          path: '/orderInclude',
          query: { id: item.id }
        })
        return
      }
      this.$router.push({
        path: '/order',
        query: { id: item.id }
      })
    }
  },
  mounted() {
    this.checkDevice()
    window.addEventListener('resize', this.checkDevice)
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.checkDevice)
  }
}
</script>

<style lang="less" scoped>
.content {
  .main {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;

    @media screen and (max-width: 750px) {
      padding: 10px;
    }
  }
}

.product-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.product-item {
  display: flex;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.3s ease;
  border-top: 1px solid #EEEEEE;
  @media screen and (max-width: 750px) {
    flex-direction: column;
  }
  &:hover {
    transform: translateY(-5px);
  }

  .product-image {
    width: 300px;
    height: 200px;
    flex-shrink: 0;
    padding: 20px 0;

    @media screen and (max-width: 750px) {
      width: 100%;
      height: 180px;
    }

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }

  .product-info {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;

    .product-name {
      font-size: 20px;
      color: #333;
      margin-bottom: 10px;
    }

    .product-desc {
      color: #666;
      font-size: 14px;
      line-height: 1.5;
      margin-bottom: 15px;
    }

    .product-meta {
      color: #666;
      font-size: 14px;
      margin-bottom: 15px;

      .duration {
        display: inline-flex;
        align-items: center;
      }
    }

    .product-footer {
      margin-top: auto;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .price {
        display: flex;
        flex-direction: column;

        .currency {
          font-size: 12px;
          color: #999;
        }

        .amount {
          font-size: 24px;
          color: #0F7CD0;
          font-weight: bold;
        }
      }

      .book-btn {
        background-color: #0F7CD0;
        border-color: #0F7CD0;
        padding: 10px 25px;

        &:hover {
          background-color: darken(#0F7CD0, 5%);
          border-color: darken(#0F7CD0, 5%);
        }
      }
    }
  }
}

.is-mobile {
  .product-item {
    .product-info {
      padding: 15px;

      .product-name {
        font-size: 18px;
      }

      .product-footer {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;

        .price {
          align-items: center;
        }

        .book-btn {
          width: 100%;
        }
      }
    }
  }
}
</style>
